package cc.yugu.yhdw.webserver.service.basic;


import cc.yugu.yhdw.common.constant.CacheKey;
import cc.yugu.yhdw.common.domain.basic.AdImage;
import cc.yugu.yhdw.webserver.persistence.basic.AdImageMapper;
import com.whalin.MemCached.MemCachedClient;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
 * 广告图片业务详情（面向切面编程）
 * 
 * @Date:Created in 2018/7/2 20:37
 * @Author:
 * @Modified By: zjn 2018/7/2 20:37
 */ 
@Component
@Aspect
public class AdImageServiceAspect {
    //注入缓存客户端
    @Autowired
    MemCachedClient memCachedClient;
    @Autowired
    AdImageMapper adImageMapper;
    //增加切点
    @Pointcut("execution(* cc.yugu.yhdw.webserver.service.basic.AdImageService.create(..))")
    private void create() {}
    //环绕
    @Around("create()")
    public Object create(ProceedingJoinPoint joinPoint) throws Throwable {
        // 这句话是执行目标方法create()
        Object result = joinPoint.proceed();

        String key = CacheKey.K_ZERO_V_AD_IMAGE_LIST;
        // 从memCachedClient缓存中按key值删除对象
        memCachedClient.delete(key);

        return result;
    }

    @Pointcut("execution(* cc.yugu.yhdw.webserver.service.basic.AdImageService.update(..))")
    private void update() {}
    @Around("update()")
    public Object update(ProceedingJoinPoint joinPoint) throws Throwable {
        // "58:0"
        String key = CacheKey.K_ZERO_V_AD_IMAGE_LIST;
        Object result = joinPoint.proceed();
        memCachedClient.delete(key);
        return result;
    }

    @Pointcut("execution(* cc.yugu.yhdw.webserver.service.basic.AdImageService.updateOrderNum(..))")
    private void updateOrderNum() {}

    @Around("updateOrderNum()")
    public Object updateOrderNum(ProceedingJoinPoint joinPoint) throws Throwable {
        Object result =  joinPoint.proceed();
        // "58:0"
        String key = CacheKey.K_ZERO_V_AD_IMAGE_LIST;
        memCachedClient.delete(key);
        return result;
    }

    @Pointcut("execution(* cc.yugu.yhdw.webserver.service.basic.AdImageService.delete(..))")
    private void delete() {}

    @Around("delete()")
    public Object delete(ProceedingJoinPoint joinPoint) throws Throwable {
        Object result = joinPoint.proceed();
        String key = CacheKey.K_ZERO_V_AD_IMAGE_LIST;
        memCachedClient.delete(key);
        return result;
    }
}
